package com.itboye.ihomebank.presenter;

import java.util.Observer;

import com.itboye.ihomebank.base.BasePresenter;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.interfaces.KeyInterface;
import com.itboye.ihomebank.responsitory.KeyRepository;

/**
 * 锁
 * 
 */
public class KeyPresenter extends BasePresenter implements
		KeyInterface<HouseBean> {

	public KeyPresenter(Observer observer) {
		super(observer);
	}

	// 注册
	public static final String register_success = UserPresenter.class.getName()
			+ "_Rregister_success";// 由此判断请求的接口
	public static final String register_fail = UserPresenter.class.getName()
			+ "_Register_fail";

	// 绑定管理员
	public static final String addMain_success = UserPresenter.class.getName()
			+ "_AddMain_success";// 由此判断请求的接口
	public static final String addMain_fail = UserPresenter.class.getName()
			+ "_AddMain_fail";
	// 开锁记录
	public static final String kaisuo_success = UserPresenter.class.getName()
			+ "_kaisuo_success";// 由此判断请求的接口
	public static final String kaisuo_fail = UserPresenter.class.getName()
			+ "_kaisuo_fail";
	// 冻结钥匙
	public static final String dongjie_success = UserPresenter.class.getName()
			+ "_dongjie_success";// 由此判断请求的接口
	public static final String dongjie_fail = UserPresenter.class.getName()
			+ "_dongjie_fail";
	// 解冻钥匙
	public static final String jiedong_success = UserPresenter.class.getName()
			+ "_jiedong_success";// 由此判断请求的接口
	public static final String jiedong_fail = UserPresenter.class.getName()
			+ "_jiedong_fail";
	// 删除钥匙
	public static final String shanchu_success = UserPresenter.class.getName()
			+ "_shanchu_success";// 由此判断请求的接口
	public static final String shanchu_fail = UserPresenter.class.getName()
			+ "_shanchu_fail";
	// 备份钥匙
	public static final String beifen_success = UserPresenter.class.getName()
			+ "_beifen_success";// 由此判断请求的接口
	public static final String beifen_fail = UserPresenter.class.getName()
			+ "_beifen_fail";

	// 重置键盘密码
	public static final String jianpanPass_success = UserPresenter.class
			.getName() + "_jianpanPass_success";// 由此判断请求的接口
	public static final String jianpanPass_fail = UserPresenter.class.getName()
			+ "_jianpanPass_fail";

	// 备份钥匙列表
	public static final String beifenList_success = UserPresenter.class
			.getName() + "_beifenList_success";// 由此判断请求的接口
	public static final String beifenList_fail = UserPresenter.class.getName()
			+ "_beifenList_fail";

	// 删除备份钥匙
	public static final String deleteBeifen_success = UserPresenter.class
			.getName() + "_deleteBeifen_success";// 由此判断请求的接口
	public static final String deleteBeifen_fail = UserPresenter.class
			.getName() + "_deleteBeifen_fail";
	// 下载备份钥匙
	public static final String downBeifen_success = UserPresenter.class
			.getName() + "_downBeifen_success";// 由此判断请求的接口
	public static final String downBeifen_fail = UserPresenter.class.getName()
			+ "_downBeifen_fail";

	// 发送键盘密码
	public static final String sendJianPanPass_success = UserPresenter.class
			.getName() + "_sendJianPanPass_success";// 由此判断请求的接口
	public static final String sendJianPanPass_fail = UserPresenter.class
			.getName() + "_sendJianPanPass_fail";
	// 意见反馈
	public static final String fankui_success = UserPresenter.class.getName()
			+ "_fankui_success";// 由此判断请求的接口
	public static final String fankui_fail = UserPresenter.class.getName()
			+ "_fankui_fail";

	// 获取锁信息
	public static final String suoXinXi_success = UserPresenter.class.getName()
			+ "_suoXinXi_success";// 由此判断请求的接口
	public static final String suoXinXi_fail = UserPresenter.class.getName()
			+ "_suoXinXi_fail";

	// 提交预约
	public static final String yuyue_success = UserPresenter.class.getName()
			+ "_yuyue_success";// 由此判断请求的接口
	public static final String yuyue_fail = UserPresenter.class.getName()
			+ "_yuyue_fail";
	// 锁推送
	public static final String tuisong_success = UserPresenter.class.getName()
				+ "_tuisong_success";// 由此判断请求的接口
	public static final String tuisong_fail = UserPresenter.class.getName()
				+ "_tuisong_fail";
	
	// 消息未读
	public static final String weidu_success = UserPresenter.class.getName()
					+ "_weidu_success";// 由此判断请求的接口
	public static final String weidu_fail = UserPresenter.class.getName()
					+ "_weidu_fail";
	
	// 消息已读
	public static final String yidu_success = UserPresenter.class.getName()
						+ "_yidu_success";// 由此判断请求的接口
	public static final String yidu_fail = UserPresenter.class.getName()
						+ "_yidu_fail";

	/**
	 * 注册
	 */
	@Override
	public void getRegister(String uid) {
		KeyInterface<HouseBean> user = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(register_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(register_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		user.getRegister(uid);
	}

	@Override
	public void getAddMain(String uid, String lock_type, String lockName,
			String lockAlias, String lockMac, String lockKey,
			String lockFlagPos, String aesKeyStr, String version) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(addMain_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(addMain_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getAddMain(uid, lock_type, lockName, lockAlias, lockMac, lockKey,
				lockFlagPos, aesKeyStr, version);

	}

	/**
	 * 开锁记录
	 */
	@Override
	public void getKaiSuoJiLu(String uid, String lock_id, String current_page,
			String per_page) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(kaisuo_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(kaisuo_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getKaiSuoJiLu(uid, lock_id, current_page, per_page);

	}

	/**
	 * 冻结钥匙
	 */
	@Override
	public void getDongJie(String uid, String to_uid, String lock_id,
			String key_id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(dongjie_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(dongjie_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getDongJie(uid, to_uid, lock_id, key_id);

	}

	/**
	 * 解冻钥匙
	 */
	@Override
	public void getJieDong(String uid, String to_uid, String lock_id,
			String key_id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(jiedong_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(jiedong_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getJieDong(uid, to_uid, lock_id, key_id);

	}

	@Override
	public void getShanChu(String uid, String to_uid, String lock_id,
			String key_id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(shanchu_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(shanchu_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getShanChu(uid, to_uid, lock_id, key_id);

	}

	@Override
	public void getBeiFei(String uid, String lock_Id, String key_id,
			String admin_ps, String nokey_ps, String delete_ps) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(beifen_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(beifen_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getBeiFei(uid, lock_Id, key_id, admin_ps, nokey_ps, delete_ps);

	}

	@Override
	public void getJianPanPass(String uid, String lock_id, String pwd_info,
			String timestamp) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(jianpanPass_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(jianpanPass_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getJianPanPass(uid, lock_id, pwd_info, timestamp);

	}

	/**
	 * 备份钥匙列表
	 */
	@Override
	public void getBeifeiList(String uid) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(beifenList_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(beifenList_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getBeifeiList(uid);

	}

	/**
	 * 删除备份钥匙
	 */
	@Override
	public void getDeleteBeiFen(String uid, String lock_id, String key_id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(deleteBeifen_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(deleteBeifen_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getDeleteBeiFen(uid, lock_id, key_id);

	}

	/**
	 * 下载备份钥匙
	 */
	@Override
	public void getDownKeyBeiFen(String uid, String lock_id, String key_id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(downBeifen_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(downBeifen_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getDownKeyBeiFen(uid, lock_id, key_id);

	}

	/**
	 * 发送键盘密码
	 */
	@Override
	public void getKeyboardPwd(String uid, String lock_id, String pwd_type,
			String to_phone, String start, String end) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(sendJianPanPass_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(sendJianPanPass_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getKeyboardPwd(uid, lock_id, pwd_type, to_phone, start, end);

	}

	@Override
	public void getFankui(String uid, String content) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(fankui_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(fankui_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getFankui(uid, content);
	}

	@Override
	public void getSuoXinXi() {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(suoXinXi_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(suoXinXi_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getSuoXinXi();

	}

	@Override
	public void getYuYue(String uid, String name, String mobile, String address) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(yuyue_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(yuyue_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getYuYue(uid,name,mobile,address);

	}

	@Override
	public void getTuiSong(String uid, String lock_id, String push) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(tuisong_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(tuisong_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getTuiSong(uid,lock_id,push);
		
	}

	@Override
	public void getWeiDu(String uid) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(weidu_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(weidu_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getWeiDu(uid);
		
	}

	@Override
	public void getYiDu(String uid, String id) {
		KeyInterface<HouseBean> key = new KeyRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(yidu_success);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(yidu_fail);
						KeyPresenter.this.setChanged();
						KeyPresenter.this.notifyObservers(result);

					}
				});
		key.getYiDu(uid,id);
		
	}

}
